]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
searchDisplay: Cache result display actors
authorJasper St. Pierre <jstpierre@mecheye.net>
Fri, 8 Feb 2013 23:59:15 +0000 (18:59 -0500)
committerJasper St. Pierre <jstpierre@mecheye.net>
Wed, 30 Oct 2013 17:01:20 +0000 (13:01 -0400)
When we create a result actor, cache it, so it can be used for
subsearches of the same initial. For now, to keep memory usage
and the stage graph relatively clean, don't persist the actors
across searches, but maybe we should do this in the future.

This also means that we don't query getResultMetas for items
that we've seen in the same initial search.

https://bugzilla.gnome.org/show_bug.cgi?id=704912

js/ui/appDisplay.js
js/ui/iconGrid.js
js/ui/search.js

index cc711bd406539f2bedf6fec72d5fc65a0706e708..7186d9f3d0a01f1a0999a36ab15eca95342aec73 100644 (file)
@@ -92,7 +92,7 @@ const BaseAppView = new Lang.Class({
     },
 
     removeAll: function() {
-        this._grid.removeAll();
+        this._grid.destroyAll();
         this._items = {};
         this._allItems = [];
     },
@@ -613,6 +613,10 @@ const FrequentView = new Lang.Class({
         return this._usage.get_most_used("").length >= MIN_FREQUENT_APPS_COUNT;
     },
 
+    removeAll: function() {
+        this._grid.destroyAll();
+    },
+
     loadApps: function() {
         let mostUsed = this._usage.get_most_used ("");
         let hasUsefulData = this.hasUsefulData();
index 8bcb56d2cf8c1b6102adc9386cec82b1890b3485..4801ac23b53c5c7ac4903fb3c0489002bdf9209c 100644 (file)
@@ -413,6 +413,11 @@ const IconGrid = new Lang.Class({
     },
 
     removeAll: function() {
+        this._items = [];
+        this._grid.remove_all_children();
+    },
+
+    destroyAll: function() {
         this._items = [];
         this._grid.destroy_all_children();
     },
index 7cd2195575961580264fcbc452185558ea3076ab..4fb03eecc7332cbc43a885b52074a08aa01dc854 100644 (file)
@@ -323,6 +323,8 @@ const SearchResultsBase = new Lang.Class({
 
         let separator = new Separator.HorizontalSeparator({ style_class: 'search-section-separator' });
         this.actor.add(separator.actor);
+
+        this._resultDisplays = {};
     },
 
     destroy: function() {
@@ -334,6 +336,7 @@ const SearchResultsBase = new Lang.Class({
     },
 
     clear: function() {
+        this._resultDisplays = {};
         this._clearResultDisplay();
         this.actor.hide();
     },
@@ -349,6 +352,27 @@ const SearchResultsBase = new Lang.Class({
     _setMoreIconVisible: function(visible) {
     },
 
+    _ensureResultActors: function(results, callback) {
+        let metasNeeded = results.filter(Lang.bind(this, function(resultId) {
+            return this._resultDisplays[resultId] === undefined;
+        }));
+
+        if (metasNeeded.length === 0) {
+            callback();
+        } else {
+            this.provider.getResultMetas(metasNeeded, Lang.bind(this, function(metas) {
+                metasNeeded.forEach(Lang.bind(this, function(resultId, i) {
+                    let meta = metas[i];
+                    let display = this._createResultDisplay(meta);
+                    display.connect('activate', Lang.bind(this, this._activateResult));
+                    display.actor.connect('key-focus-in', Lang.bind(this, this._keyFocusIn));
+                    this._resultDisplays[resultId] = display;
+                }));
+                callback();
+            }));
+        }
+    },
+
     updateSearch: function(providerResults, terms, callback) {
         this._terms = terms;
 
@@ -361,15 +385,17 @@ const SearchResultsBase = new Lang.Class({
             let results = this.provider.filterResults(providerResults, maxResults);
             let hasMoreResults = results.length < providerResults.length;
 
-            this.provider.getResultMetas(results, Lang.bind(this, function(metas) {
-                this.clear();
+            this._ensureResultActors(results, Lang.bind(this, function() {
+                this._clearResultDisplay();
 
                 // To avoid CSS transitions causing flickering when
                 // the first search result stays the same, we hide the
                 // content while filling in the results.
                 this.actor.hide();
                 this._clearResultDisplay();
-                this._renderResults(metas);
+                results.forEach(Lang.bind(this, function(resultId) {
+                    this._addItem(this._resultDisplays[resultId]);
+                }));
                 this._setMoreIconVisible(hasMoreResults && this.provider.canLaunchSearch);
                 this.actor.show();
                 callback();
@@ -414,17 +440,16 @@ const ListSearchResults = new Lang.Class({
         return MAX_LIST_SEARCH_RESULTS_ROWS;
     },
 
-    _renderResults: function(metas) {
-        for (let i = 0; i < metas.length; i++) {
-            let display = new ListSearchResult(this.provider, metas[i]);
-            display.connect('activate', Lang.bind(this, this._activateResult));
-            display.actor.connect('key-focus-in', Lang.bind(this, this._keyFocusIn));
-            this._content.add_actor(display.actor);
-        }
+    _clearResultDisplay: function () {
+        this._content.remove_all_children();
     },
 
-    _clearResultDisplay: function () {
-        this._content.destroy_all_children();
+    _createResultDisplay: function(meta) {
+        return new ListSearchResult(this.provider, meta);
+    },
+
+    _addItem: function(display) {
+        this._content.add_actor(display.actor);
     },
 
     getFirstResult: function() {
@@ -468,6 +493,14 @@ const GridSearchResults = new Lang.Class({
         this._grid.removeAll();
     },
 
+    _createResultDisplay: function(meta) {
+        return new GridSearchResult(this.provider, meta);
+    },
+
+    _addItem: function(display) {
+        this._grid.addItem(display.actor);
+    },
+
     getFirstResult: function() {
         if (this._grid.visibleItemsCount() > 0)
             return this._grid.getItemAtIndex(0)._delegate;